//------------Sonic CD Tube Switch Script-------------//
//--------Scripted by Christian Whitehead 'The Taxman'--------//
//-------Unpacked By Rubberduckycooly's Script Unpacker-------//

//-------Aliases-------//
#alias 44: TYPE_TUBESWITCH
#alias Player.Value6:Player.MinRollSpeed


sub ObjectPlayerInteraction
	PlayerObjectCollision(C_TOUCH,-16,-16,16,16)
	if CheckResult==1
		switch Object.PropertyValue
		case 0
			if Player.Speed>0
				if Player.State!=PlayerObject_Tunnel
					PlaySfx(7,0)
				endif
				Player.Direction=FACING_RIGHT
				Player.State=PlayerObject_Tunnel
				Player.Animation=ANI_JUMPING
				Player.MinRollSpeed=655360
				if Player.Speed<655360
					Player.Speed=655360
				endif
			else
				if Player.Gravity==0
					if Player.Speed>-131072
						Player.Speed=-131072
					endif
				endif
				Player.State=PlayerObject_HandleRolling
				Player.Animation=ANI_JUMPING
			endif
			break
		case 1
			if Player.State!=PlayerObject_Tunnel
				PlaySfx(7,0)
			endif
			Player.Gravity=0
			Player.State=PlayerObject_Tunnel
			Player.Animation=ANI_JUMPING
			Player.CollisionMode=3
			Player.Angle=64
			Player.Speed=1048576
			Player.MinRollSpeed=1048576
			break
		case 2
			if Object.Value0==0
				if Player.CollisionMode==0
					Player.CollisionMode=2
					FlipSign(Player.Speed)
					Player.Angle=128
				else
					Player.CollisionMode=0
					FlipSign(Player.Speed)
					Player.Angle=0
					Player.YPos+=262144
				endif
				Player.State=PlayerObject_Tunnel
				Player.Animation=ANI_JUMPING
			endif
			break
		case 3
			if Player.YVelocity<0
				Player.Gravity=0
				Player.State=PlayerObject_Tunnel
				Player.Animation=ANI_JUMPING
				Player.CollisionMode=1
				Player.Angle=192
				Player.MinRollSpeed=655360
				Player.Speed=Player.YVelocity
				FlipSign(Player.Speed)
			endif
			break
		case 4
			if Player.Speed<0
				if Player.State!=PlayerObject_Tunnel
					PlaySfx(7,0)
				endif
				Player.State=PlayerObject_Tunnel
				Player.Animation=ANI_JUMPING
				Player.MinRollSpeed=655360
			else
				Player.State=PlayerObject_HandleRolling
				Player.Animation=ANI_JUMPING
			endif
			break
		case 5
			if Player.Gravity==1
				Player.XVelocity=Object.Value1
				Player.Speed=Object.Value1
			else
				if Player.CollisionMode==1
					Player.Angle=196
					Cos256(TempValue0,Player.Angle)
					TempValue0*=Player.Speed
					TempValue0>>=8
					if TempValue0!=0
						Object.Value1=TempValue0
					endif
				endif
			endif
			break
		case 6
			if Player.State==PlayerObject_Tunnel
				if Player.YVelocity<-393216
					Player.YVelocity=-393216
				endif
			else
				Player.Animation=ANI_JUMPING
			endif
			break
		case 7
			if Player.State==PlayerObject_Tunnel
				Object.PropertyValue=8
			endif
			break
		case 8
			if Player.Gravity==1
				Player.YVelocity=-688128
				Object.PropertyValue=7
			endif
			break

		endswitch
		Object.Value0=1
	else
		Object.Value0=0
	endif
endsub

sub RSDK
	LoadSpriteSheet("Global/Display.gif")
	SetEditorIcon(Icon0,SingleIcon,-16,-16,32,32,1,143)
endsub
